package com.dein.music.service.impl;

import com.dein.music.dao.MusicPreferenceDao;
import com.dein.music.model.Music;
import com.dein.music.model.MusicPreference;
import com.dein.music.service.MusicPreferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("musicPreferenceService")
public class MusicPreferenceMusicImpl implements MusicPreferenceService {

    protected MusicPreferenceDao musicPreferenceDao;


    @Autowired
    @Qualifier("musicPreferenceDao")
    public void setUserDao(MusicPreferenceDao musicPreferenceDao)
    {
        this.musicPreferenceDao = musicPreferenceDao;
    }

    @Override
    public boolean addPreferenceMusic(Long userId,Long musicId, float preference) {
        try{
            musicPreferenceDao.addPreferenceMusic(userId, musicId, preference);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean deletePreferenceMusic(Long userId, Long musicId) {
        try{
            musicPreferenceDao.deletePreferenceMusic(userId, musicId);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public List<Music> getPreferenceMusicList(Long userId,Integer limit,Integer start) {
        try{
            return musicPreferenceDao.getPreferenceMusicList(userId,limit,start);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public Integer countPreferenceMusic(Long userId) {
        try{
            return musicPreferenceDao.countPreferenceMusic(userId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean preferenceMusicExist(Long userId, Long musicId) {
        try {
            if(musicPreferenceDao.preferenceMusicExist(userId, musicId)>0)
                return  true;
            else
                return  false;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
